{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "\n",
    "方法名称|说明\n",
    ":-|:-\n",
    ".loc[]|基于标签索引选取数据\n",
    ".iloc[]|基于整数索引选取数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "            A           B           C           D           E           F  \\\n",
      "a  -17.865749  119.081569  223.429788  -41.264090  198.043913 -153.802602   \n",
      "b   99.688857 -172.130752 -147.831304  -49.370203  -36.016494  -31.578055   \n",
      "c   53.361955  196.312870  140.800281   44.868824  -60.741063  108.022721   \n",
      "d   58.533716    6.408827  -24.713782  -42.646268 -144.835167  -12.565502   \n",
      "e  -72.370672  -75.131504  -67.205425  -31.574775  -85.734234   58.528404   \n",
      "f -111.523686 -222.161845  -19.577246  -85.097956  109.260223   24.174643   \n",
      "g -259.487836  179.362134    0.627296   90.726925   78.745531  -21.428689   \n",
      "h    1.956300  -25.827095  106.932698  153.554897   59.266380  129.435318   \n",
      "i  -38.098542  -58.977479   -0.448784  106.374272  -42.311471  -93.420582   \n",
      "j  238.046880  -91.097491  -38.392283  -59.422381  107.984077  -30.211721   \n",
      "\n",
      "            G           H           I           K           L  \n",
      "a  143.621554  178.966435   89.157661   10.073674  105.412209  \n",
      "b   15.992768  -95.865173   27.011870  -97.190845 -115.990779  \n",
      "c  -63.124035  -13.817382  -35.871680  119.008161   12.540880  \n",
      "d  -56.880833  -38.630794   29.544987   75.976316   60.736694  \n",
      "e   62.047014   14.745272  -70.244403  152.025367  178.440975  \n",
      "f  175.594320   71.589095   95.129070   59.606469 -115.310434  \n",
      "g -230.701811 -151.541779 -124.839523 -285.349448  -19.124789  \n",
      "h  204.691518   53.586830 -226.761392  -48.348175 -136.832440  \n",
      "i -171.016443  134.963970  -35.034138   12.538971   -4.263997  \n",
      "j  -44.544610  -27.812344  -62.522020   66.845978 -137.845775  \n"
     ]
    }
   ],
   "source": [
    "df = pd.DataFrame({\n",
    "    \"A\":pd.Series(np.random.randn(10)*100,index=list(\"abcdefghij\")),\n",
    "    \"B\":pd.Series(np.random.randn(10)*100,index=list(\"abcdefghij\")),\n",
    "    \"C\":pd.Series(np.random.randn(10)*100,index=list(\"abcdefghij\")),\n",
    "    \"D\":pd.Series(np.random.randn(10)*100,index=list(\"abcdefghij\")),\n",
    "    \"E\":pd.Series(np.random.randn(10)*100,index=list(\"abcdefghij\")),\n",
    "    \"F\":pd.Series(np.random.randn(10)*100,index=list(\"abcdefghij\")),\n",
    "    \"G\":pd.Series(np.random.randn(10)*100,index=list(\"abcdefghij\")),\n",
    "    \"H\":pd.Series(np.random.randn(10)*100,index=list(\"abcdefghij\")),\n",
    "    \"I\":pd.Series(np.random.randn(10)*100,index=list(\"abcdefghij\")),\n",
    "    \"G\":pd.Series(np.random.randn(10)*100,index=list(\"abcdefghij\")),\n",
    "    \"K\":pd.Series(np.random.randn(10)*100,index=list(\"abcdefghij\")),\n",
    "    \"L\":pd.Series(np.random.randn(10)*100,index=list(\"abcdefghij\"))\n",
    "})\n",
    "print(df)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "           A           B           C\n",
      "a -17.865749  119.081569  223.429788\n",
      "b  99.688857 -172.130752 -147.831304\n",
      "            A           B           C          D\n",
      "a  -17.865749  119.081569  223.429788 -41.264090\n",
      "b   99.688857 -172.130752 -147.831304 -49.370203\n",
      "c   53.361955  196.312870  140.800281  44.868824\n",
      "d   58.533716    6.408827  -24.713782 -42.646268\n",
      "e  -72.370672  -75.131504  -67.205425 -31.574775\n",
      "f -111.523686 -222.161845  -19.577246 -85.097956\n"
     ]
    }
   ],
   "source": [
    "clip1 = df.loc[\"a\":\"b\",\"A\":\"C\"]\n",
    "print(clip1)\n",
    "clip2 = df.loc[[\"a\",\"b\",\"c\",\"d\",\"e\",\"f\"],[\"A\",\"B\",\"C\",\"D\"]]\n",
    "print(clip2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "            C          D           E           F\n",
      "a  223.429788 -41.264090  198.043913 -153.802602\n",
      "b -147.831304 -49.370203  -36.016494  -31.578055\n",
      "c  140.800281  44.868824  -60.741063  108.022721\n",
      "d  -24.713782 -42.646268 -144.835167  -12.565502\n",
      "e  -67.205425 -31.574775  -85.734234   58.528404\n"
     ]
    }
   ],
   "source": [
    "clip = df.iloc[0:5,2:6]\n",
    "print(clip)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
